package com.example.util;
 
import com.example.pojo.redis.Student;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Tuple;

import java.util.ArrayList;
import java.util.Set;

/**
 * @author 小苏
 * @ClassName:RedisController
 * @description: TODO
 * @data 2022/12/28 9:20
 * @version: 1.0
 **/
public class RankingList {
    public static void main(String[] args) {
        //创建Jedis实例
        Jedis jedis = new Jedis("47.104.155.187",6388);
        jedis.auth("test123");
        System.out.println("Redis连接成功");
        try {
            //Redis键
            String key = "BLOG_KEY";
            //清理可能已有的键
            jedis.del(key);
            //模拟生成多个学生
            ArrayList<Student> bloggers = new ArrayList<>();
            Student one = new Student("小二",1);
            Student two = new Student("小五",2);
            Student three = new Student("小七",3);
            Student four = new Student("小六",4);
            Student file = new Student("小晚",5);
            bloggers.add(one);
            bloggers.add(two);
            bloggers.add(three);
            bloggers.add(four);
            bloggers.add(file);


            //记录每个学生的随机数
            for(int j=0; j<bloggers.size(); j++) {
                //模拟生成学生随机数
                int score = (int) (Math.random() * 100);
                Student blogger = bloggers.get(j);
                for (int i = 4; i < bloggers.size(); i++) {
                    System.out.println("学生姓名：" + blogger.getName() + "，幸运值：" + score);
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            jedis.quit();
            jedis.close();
        }
    }
}